<?php
/**
* @file $Id: DailySummary.php 550 2007-06-04 05:11:04Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

DrawHeader(ProgramTitle());

if(!function_exists('_makeColor'))
{
	function _makeColor($value,$column)
	{	global $THIS_RET,$RET,$attendance_codes,$schools_extra,$enrollment_RET,$absent_count,$pres_count;
	
		$date = strtoupper(substr($column,1,4).'-'.substr($column,5,2).'-'.substr($column,7));
	
		$enrolled = false;
		foreach($enrollment_RET[$THIS_RET['STUDENT_ID']] as $record)
		{
			if($record['END_DATE'] && $date > $record['END_DATE'])
				continue;
			if($date >= $record['START_DATE'])
			{
				$enrolled = true;
				break;
			}
		}
	
		if($_REQUEST['period_id'])
		{
			if(!$attendance_codes)
				$attendance_codes = DBGet(DBQuery("SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME,TYPE,TITLE FROM ATTENDANCE_CODES WHERE SYEAR='".UserSyear()."' AND ".$schools_extra." AND TABLE_NAME='0'"),array(),array('ID'));
	
			if($enrolled == false)
			{
				if($RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE'])
					$val = _makeCodePulldown($RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE'],$THIS_RET['STUDENT_ID'],$column);
				else
					$val = ' - ';

				$rollover = '<DIV style="background-color:#BBBBBB;font-size:-2;" onMouseOver=\'stm(["","'._('Not Enrolled').'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>';

				return $rollover."".$val."".'</DIV>';
			}
			elseif($attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['DEFAULT_CODE']=='Y' || ($attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['STATE_CODE']=='P' || $attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['TYPE']=='official'))
			{
				$pres_count[$date]++;
				$rollover = '<DIV style="background-color:#00FF00;font-size:-2;" onMouseOver=\'stm(["","'.$attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['TITLE'].'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>';
				return $rollover.""._makeCodePulldown($RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE'],$THIS_RET['STUDENT_ID'],$column)."</DIV>";
			}
			elseif($attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['STATE_CODE']=='P')
			{
				$pres_count[$date]++;
				$rollover = '<DIV style="background-color:#FFCC00;font-size:-2;" onMouseOver=\'stm(["","'.$attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['TITLE'].'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>';
				return $rollover.""._makeCodePulldown($RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE'],$THIS_RET['STUDENT_ID'],$column)."</DIV>";
			}
			elseif($attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['STATE_CODE']=='A')
			{
				$absent_count[$date]++;
				$rollover = '<DIV style="background-color:#FF0000;font-size:-2;" onMouseOver=\'stm(["","'.$attendance_codes[$RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE']][1]['TITLE'].'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>';
				return $rollover.""._makeCodePulldown($RET[$THIS_RET['STUDENT_ID']][$column][1]['ATTENDANCE_CODE'],$THIS_RET['STUDENT_ID'],$column)."</DIV>";
			}
			else
			{
				$rollover = '<DIV onMouseOver=\'stm(["","'._('Attendance was not taken.  Assumed Present').'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>';
				return $rollover.'<font color=gray>P</font></DIV>';
			}
		}
		else
		{
			if($enrolled == false)
				return "<TABLE bgcolor=#BBBBBB cellpadding=0 cellspacing=0 width=10 class=innerLO_field><TR><TD> - </TD></TR></TABLE>";
			elseif($RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE']=='0.0')
			{
				$absent_count[$date]++;
				return "<TABLE bgcolor=#FF0000 cellpadding=0 cellspacing=0 width=10 class=innerLO_field><TR><TD>A</TD></TR></TABLE>";
			}
			elseif($RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE'] > 0 && $RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE'] < 1)
			{
				$absent_count[$date] += (1-$RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE']);
				$pres_count[$date] += $RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE'];
				return "<TABLE bgcolor=#FFCC00 cellpadding=0 cellspacing=0 width=10 class=innerLO_field><TR><TD>H</TD></TR></TABLE>";
			}
			elseif($RET[$THIS_RET['STUDENT_ID']][$column][1]['STATE_VALUE'] == 1)
			{
				$pres_count[$date]++;
				return "<TABLE bgcolor=#00FF00 cellpadding=0 cellspacing=0 width=10 class=innerLO_field><TR><TD>P</TD></TR></TABLE>";
			}
		}
	}
	
	// IF A STUDENT IS CHOSEN
	function _makePeriodColor($name,$state_code,$default_code)
	{	global $absent_count;
	
		if($state_code=='A' || $state_code=='0.0')
			$color = '#FF0000';
		elseif($default_code=='Y' || $state_code=='1.0')
			$color='#00FF00';
		elseif($state_code=='P' || is_numeric($state_code))
			$color = '#FFCC00';
		
		if($color && $state_code!='1.0')
			return "<TABLE bgcolor=$color cellpadding=0 cellspacing=0  width=10 class=innerLO_field><TR><TD>$name</TD></TR></TABLE>";
		else
			return false;
	}
	
	function _makeCodePulldown($value,$student_id,$date)
	{	global $THIS_RET,$attendance_codes,$_FOCUS;
	
		$date = substr($date,1,4).'-'.substr($date,5,2).'-'.substr($date,7);
	
		if(!$_FOCUS['code_options'])
		{
			foreach($attendance_codes as $id=>$code)
				$_FOCUS['code_options'][$id] = $code[1]['SHORT_NAME'];
		}
	
		return SelectInput($value,'attendance['.$student_id.']['.$date.'][ATTENDANCE_CODE]','',$_FOCUS['code_options']);
	}
	
	function _makeName($value,$column)
	{
		if(!$_REQUEST['_FOCUS_PDF'] || $_REQUEST['LO_save']=='1')
			return $value;
		else
			return '<font size=-2 class=innerLO_field>'.str_replace(' ','&nbsp;',substr(trim($value),0,strpos($value,',')+3)).'</font>';
	}
}

if($_REQUEST['day_start'] && $_REQUEST['month_start'] && $_REQUEST['year_start'])
{
	while(!VerifyDate($start_date = $_REQUEST['day_start'].'-'.$_REQUEST['month_start'].'-'.$_REQUEST['year_start']))
		$_REQUEST['day_start']--;
}
elseif(!$start_date)
	$start_date = '01-'.strtoupper(date('M-y'));

if($_REQUEST['day_end'] && $_REQUEST['month_end'] && $_REQUEST['year_end'])
{
	while(!VerifyDate($end_date = $_REQUEST['day_end'].'-'.$_REQUEST['month_end'].'-'.$_REQUEST['year_end']))
		$_REQUEST['day_end']--;
}
elseif(!$end_date)
	$end_date = DBDate();

if(UserSchool() && $_REQUEST['_search_all_schools']!='Y')
	$schools_extra = " SCHOOL_ID='".UserSchool()."' ";
else
{
	$schools = substr(str_replace(",","','",User('SCHOOLS')),2,-2);
	if($schools)
		$schools_extra .= " SCHOOL_ID IN ($schools) ";
	else
		$schools_extra = 'true';
}

if($_REQUEST['attendance'] && $_POST['attendance'] && AllowEdit())
{
	foreach($_REQUEST['attendance'] as $student_id=>$values)
	{
		foreach($values as $school_date=>$columns)
		{
			$sql = "UPDATE ATTENDANCE_PERIOD SET ADMIN='Y',";
			
			foreach($columns as $column=>$value)
				$sql .= $column."='".str_replace("\'","''",$value)."',";

			$sql = substr($sql,0,-1) . " WHERE SCHOOL_DATE='".$school_date."' AND PERIOD_ID='".$_REQUEST['period_id']."' AND STUDENT_ID='".$student_id."'";
			DBQuery($sql);
			UpdateAttendanceDaily($student_id,$school_date);
		}
	}
	$current_RET = DBGet(DBQuery("SELECT ATTENDANCE_TEACHER_CODE,ATTENDANCE_CODE,ATTENDANCE_REASON,STUDENT_ID,ADMIN,COURSE_PERIOD_ID FROM ATTENDANCE_PERIOD WHERE SCHOOL_DATE='".$date."'"),array(),array('STUDENT_ID','COURSE_PERIOD_ID'));
	unset($_REQUEST['attendance']);
}

if(($_REQUEST['search_modfunc'] && $_REQUEST['search_modfunc']!='search') || $_REQUEST['student_id'] || UserStudentID() || User('PROFILE')=='parent' || User('PROFILE')=='student')
{
	$PHP_tmp_SELF = PreparePHP_SELF();
	$extraM .= "";
	if(!UserStudentID() && !$_REQUEST['student_id'])
	{
		$period_select = " : <SELECT name=period_id onchange='this.form.submit();'><OPTION value=\"\">"._('Daily')."</OPTION>";
		if($_REQUEST['_search_all_schools']=='Y')
		{
			$short_names_RET = DBGet(DBQuery("SELECT PERIOD_ID,TITLE,SHORT_NAME FROM SCHOOL_PERIODS WHERE SYEAR='".UserSyear()."' AND ".$schools_extra." ORDER BY SORT_ORDER"),array(),array('SHORT_NAME'));
			$periods_RET[0] = '';
			foreach($short_names_RET as $short_name=>$periods)
				$periods_RET[] = $periods[1];
			unset($periods_RET[0]);
		}
		else
			$periods_RET = DBGet(DBQuery("SELECT PERIOD_ID,TITLE,SHORT_NAME FROM SCHOOL_PERIODS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."' ORDER BY SORT_ORDER"));

		if(count($periods_RET)>1)
		{
			foreach($periods_RET as $period)
			{
				$period_select .= "<OPTION value=".$period['PERIOD_ID'].(($_REQUEST['period_id']==$period['PERIOD_ID'])?' SELECTED':'').">".$period['TITLE'].'</OPTION>';
				if($_REQUEST['_FOCUS_PDF']=='true' && ($_REQUEST['period_id']==$period['PERIOD_ID']))
				{
					$period_select = ': '.$period['TITLE'];
					break;
				}
			}
			//if(!$_REQUEST['_FOCUS_PDF'] && is_numeric($_REQUEST['period_id']))
				$period_select .= '</SELECT>';
		}
		elseif(count($periods_RET)==1)
		{
			foreach($periods_RET as $period)
				$period_select .= "<OPTION value=".$period['PERIOD_ID'].(($_REQUEST['period_id']==$period['PERIOD_ID'] || !isset($_REQUEST['period_id']))?' SELECTED':'').">".$period['TITLE'].'</OPTION>';

			if(!isset($_REQUEST['period_id']))
				$_REQUEST['period_id'] = $period['PERIOD_ID'];
			$period_select .= '</SELECT>';
		}
		else
			$period_select .= '</SELECT>';
	}
	echo "<FORM action=$PHP_tmp_SELF method=POST>";
	DrawHeader(' &nbsp; &nbsp; <B>'._('Report Timeframe').': </B>'.PrepareDate($start_date,'_start').' - '.PrepareDate($end_date,'_end').$period_select.' <INPUT type=submit value='._('Update').'>');
}

if($_REQUEST['period_id']=='PERIOD')
	$periods_extra = 'true';
elseif($_REQUEST['period_id'] && $_REQUEST['_search_all_schools']=='Y')
{
	$short_name_RET = DBGet(DBQuery("SELECT SHORT_NAME FROM SCHOOL_PERIODS WHERE PERIOD_ID='".$_REQUEST['period_id']."'"));
	if($short_name_RET[1]['SHORT_NAME'])
	{
		$ids_RET = DBGet(DBQuery("SELECT PERIOD_ID FROM SCHOOL_PERIODS WHERE SHORT_NAME='".$short_name_RET[1]['SHORT_NAME']."' AND ".$schools_extra));
		foreach($ids_RET as $id)
			$periods_extra .= "'".$id['PERIOD_ID']."',";
		$periods_extra = 'PERIOD_ID IN ('.substr($periods_extra,0,-1).')';
	}
	else
		$periods_extra .= "PERIOD_ID='".$_REQUEST['period_id']."'";
}
else
	$periods_extra = "PERIOD_ID='".$_REQUEST['period_id']."'";

$cal_RET = DBGet(DBQuery("SELECT DISTINCT SCHOOL_DATE,'_'||to_char(SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE FROM ATTENDANCE_CALENDAR WHERE ".$schools_extra." AND SCHOOL_DATE BETWEEN '$start_date' AND '$end_date' ORDER BY SCHOOL_DATE"));

if(UserStudentID() || $_REQUEST['student_id'] || User('PROFILE')=='parent')
{
	// JUST TO SET USERSTUDENTID()
	Search('student_id');
	$sql = "SELECT 
			cp.TITLE as COURSE_PERIOD,sp.TITLE as PERIOD,cp.PERIOD_ID,cp.DAYS
		FROM 
			SCHEDULE s,COURSES c,COURSE_PERIODS cp,SCHOOL_PERIODS sp
		WHERE
			s.COURSE_ID = c.COURSE_ID AND s.COURSE_ID = cp.COURSE_ID
			AND s.COURSE_PERIOD_ID = cp.COURSE_PERIOD_ID AND cp.PERIOD_ID = sp.PERIOD_ID
			AND s.SYEAR = c.SYEAR ".(GetAllMP('QTR',UserMP())?"AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).")":'')."
			AND s.STUDENT_ID='".UserStudentID()."' AND s.SYEAR='".UserSyear()."' 
			AND ('".DBDate()."' BETWEEN s.START_DATE AND s.END_DATE OR s.END_DATE IS NULL)
		ORDER BY sp.SORT_ORDER
		";
	$schedule_RET = DBGet(DBQuery($sql));
	for($i=count($schedule_RET);$i>=1;$i--)
	{
		$schedule_RET[$i+1] = $schedule_RET[$i];
	}
	$schedule_RET[1] = array('COURSE_PERIOD'=>_('Daily Attendance Value'),'PERIOD_ID'=>'0');
	
	$sql = "SELECT ap.SCHOOL_DATE,ap.PERIOD_ID,ac.SHORT_NAME,ac.STATE_CODE,ac.DEFAULT_CODE FROM ATTENDANCE_PERIOD ap,ATTENDANCE_CODES ac WHERE ap.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND ap.ATTENDANCE_CODE=ac.ID AND ap.STUDENT_ID='".UserStudentID()."'";
	$attendance_RET = DBGet(DBQuery($sql),array(),array('SCHOOL_DATE','PERIOD_ID'));
	$daily_RET = DBGet(DBQuery("SELECT ad.SCHOOL_DATE,'0' AS PERIOD_ID,ad.STATE_VALUE AS STATE_CODE,".db_case(array('ad.STATE_VALUE',"'0.0'","'A'","'1.0'","'P'","'H'"))." AS SHORT_NAME FROM ATTENDANCE_DAY ad WHERE ad.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND ad.STUDENT_ID='".UserStudentID()."'"));

	foreach($daily_RET as $day)
	{
		$attendance_RET[$day['SCHOOL_DATE']][0][1] = array('SCHOOL_DATE'=>$day['SCHOOL_DATE'],'PERIOD_ID'=>0,'STATE_CODE'=>$day['STATE_CODE'],'SHORT_NAME'=>$day['SHORT_NAME']);
	}
	$i = 0;
	if(count($schedule_RET))
	{
		foreach($schedule_RET as $course)
		{
			$i++;
			$student_RET[$i]['TITLE'] = $course['COURSE_PERIOD']; 
			foreach($cal_RET as $value)
			{
				$date = $value['SHORT_DATE'];
				$time = mktime(0,0,0,(substr($date,4,2)*1),(substr($date,6,2)*1),substr($date,2,2));
				$day = date('D',$time);
				switch($day)
				{
					case 'Sun':
						$day = 'U';
					break;
					case 'Thu':
						$day = 'H';
					break;
					default:
						$day = substr($day,0,1);
					break;
				}
				if(strpos($course['DAYS'],$day)!==false || $course['PERIOD_ID']=='0')
					$student_RET[$i][$value['SHORT_DATE']] = _makePeriodColor($attendance_RET[$value['SCHOOL_DATE']][$course['PERIOD_ID']][1]['SHORT_NAME'],$attendance_RET[$value['SCHOOL_DATE']][$course['PERIOD_ID']][1]['STATE_CODE'],$attendance_RET[$value['SCHOOL_DATE']][$course['PERIOD_ID']][1]['DEFAULT_CODE']);
			}
		}
	}
	
	$columns = array('TITLE'=>_('Course'));
	if(count($cal_RET))
	{
		foreach($cal_RET as $value)
			$columns[$value['SHORT_DATE']] = ShortDate($value['SCHOOL_DATE']);
	}
	
	ListOutput($student_RET,$columns);

}
else
{
	if(!$_REQUEST['period_id'])
	{
		$sql = "SELECT ad.STATE_VALUE,ad.STUDENT_ID,SCHOOL_DATE,'_'||to_char(ad.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm WHERE ad.STUDENT_ID=ssm.STUDENT_ID ";
		if($_REQUEST['include_inactive']!='Y')
			$sql .= " AND (('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) AND '".DBDate()."'>=ssm.START_DATE) ";
		$sql .= " AND ".str_replace('SCHOOL_ID','ssm.SCHOOL_ID',$schools_extra)." AND SCHOOL_DATE BETWEEN '$start_date' AND '$end_date' ";
		$RET = DBGet(DBQuery($sql),array(),array('STUDENT_ID','SHORT_DATE'));
	}
	else
	{
		$sql = "SELECT ap.ATTENDANCE_CODE,ap.STUDENT_ID,ap.SCHOOL_DATE,'_'||to_char(ap.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE FROM ATTENDANCE_PERIOD ap,STUDENT_ENROLLMENT ssm,STUDENTS s WHERE s.STUDENT_ID=ssm.STUDENT_ID AND ap.STUDENT_ID=ssm.STUDENT_ID AND ap.SCHOOL_DATE BETWEEN '$start_date' AND '$end_date' AND ".str_replace('PERIOD_ID','ap.PERIOD_ID',$periods_extra);
		if($_REQUEST['include_inactive']!='Y')
			$sql .= " AND (('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) AND '".DBDate()."'>=ssm.START_DATE) ";
		//if($_REQUEST['_search_all_schools']!='Y')
		//	$sql .= " AND ssm.SCHOOL_ID='".UserSchool()."' ";
		$sql .= ' AND '.str_replace('SCHOOL_ID','ssm.SCHOOL_ID',$schools_extra);
		$sql = appendSQL($sql,array('NoSearchTerms'=>true));
		$RET = DBGet(DBQuery($sql),array(),array('STUDENT_ID','SHORT_DATE'));
	}

/*	Widgets('course');
	Widgets('absences');	
*/
	$extra['functions']['FULL_NAME'] = '_makeName';
	Widgets('all');
	$enrollment_extra = $extra;

	$columns = array('FULL_NAME'=>_('Student'),'STUDENT_ID'=>_('Student ID'),'GRADE_ID'=>_('Grade'));
	$link['FULL_NAME']['link'] = "Modules.php?modname=$_REQUEST[modname]&day_start=$_REQUEST[day_start]&day_end=$_REQUEST[day_end]&month_start=$_REQUEST[month_start]&month_end=$_REQUEST[month_end]&year_start=$_REQUEST[year_start]&year_end=$_REQUEST[year_end]&period_id=$_REQUEST[period_id]";
	$link['FULL_NAME']['variables'] = array('student_id'=>'STUDENT_ID','school_id'=>'SCHOOL_ID');
	if(count($cal_RET))
	{
		foreach($cal_RET as $value)
		{
			$extra['SELECT'] .= ",'' as _".str_replace('-','',$value['SCHOOL_DATE']);
			$columns['_'.str_replace('-','',$value['SCHOOL_DATE'])] = ShortDate($value['SCHOOL_DATE']);
			$extra['functions']['_'.str_replace('-','',$value['SCHOOL_DATE'])] = '_makeColor';
		}
		if(count($columns)>15)
		{
			unset($columns['GRADE_ID']);
			$columns['STUDENT_ID'] = _('Stu ID');
		}
	}

	if($_REQUEST['search_modfunc']=='list')
	{
		$enrollment_extra['SELECT'] .= ',to_char(ssm.START_DATE,\'YYYY-MM-DD\') AS START_DATE,to_char(ssm.END_DATE,\'YYYY-MM-DD\') AS END_DATE,ssm.ID';
		$enrollment_extra['group'] = array('STUDENT_ID');
		$enrollment_extra['ORDER_BY'] = 'START_DATE';
		$include_inactive = $_REQUEST['include_inactive'];
		$_REQUEST['include_inactive'] = 'Y';
		$enrollment_RET = GetStuList($enrollment_extra);
		$_REQUEST['include_inactive'] = $include_inactive;
	}

	$extra['new'] = true;
	if($_REQUEST['search_modfunc']!='list')
		Search('student_id',$extra);
	else
	{
		$RET = GetStuList($extra);
		$link['add']['html']['FULL_NAME'] = '<b>'._('Total Abs<BR>Total Pres').'</b>';
		foreach($cal_RET as $value)
			$link['add']['html']['_'.str_replace('-','',$value['SCHOOL_DATE'])] = '<font size=-1><B>'.($absent_count[$value['SCHOOL_DATE']]?$absent_count[$value['SCHOOL_DATE']]:'0').'</B><BR><B>'.($pres_count[$value['SCHOOL_DATE']]?$pres_count[$value['SCHOOL_DATE']]:'0').'</B></font>';		

		// Search could probably do this too, but for now, we'll just copy-and-paste some code
		$tmp_REQUEST = $_REQUEST;
		unset($tmp_REQUEST['expanded_view']);
		unset($tmp_REQUEST['search_modfunc']);

		$programs = array(PreparePHP_SELF($tmp_REQUEST).'&amp;search_modfunc=search'=>_('Search Screen'),PreparePHP_SELF($tmp_REQUEST).'&amp;search_modfunc=list&amp;expanded_view=false'=>_('Simple List'));
		foreach($programs as $modname=>$title)
		{
			if($_REQUEST['search_modfunc']=='list' && $modname==PreparePHP_SELF($tmp_REQUEST).'&amp;search_modfunc=list&amp;expanded_view=false')
			{
				$tabcolor = Preferences('HIGHLIGHT');
				$textcolor = 'FFFFFF';
			}
			else
			{
				$tabcolor = 'DFDFDF';
				$textcolor = '666666';
			}
	
			$header .= '<TD width=10></TD><TD>'.DrawTab($title,$modname,$tabcolor,$textcolor,'_circle',array('tabcolor'=>Preferences('HIGHLIGHT'),'textcolor'=>'FFFFFF')).'</TD>';
		}
		
		if(!$_REQUEST['_FOCUS_PDF'])
			echo TabsHeader($header);

		
		ListOutput($RET,$columns,_('Student'),_('Students'),$link,array(),array('yscroll'=>true));
	}
	if(($_REQUEST['search_modfunc'] && $_REQUEST['search_modfunc']!='search') || $_REQUEST['student_id'] || UserStudentID() || User('PROFILE')=='parent' || User('PROFILE')=='student')
		echo '</FORM>';
}

?>